'use strict';
app.service('goodsAuditService',['$q','utilService',function($q,utilService){
    //查询商品分类下拉框
    this.getList = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain +  'type/select',
            params:{shopId:$scope.goods.shopId}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错");
        });
        return deferred.promise;
    }

    //查询预约信息
    this.checkReserve = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'goods/serve/id',
            params:{serveId:$scope.id}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    }

    //查询店铺下拉框
    this.getShopList = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain +  'shop/get/list'
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错");
        });
        return deferred.promise;
    }

    //审核通过或拒绝
    this.changeStatus = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'goods/edit/status',
            data:$scope.data,
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    //批量审核通过或拒绝
    this.batchUpdateUpStatus= function ($scope) {
        var updateSelect=new Array();
        for(var i=0;i<$scope.selected.length;i++){
            if($scope.selected[i].status==2){
                updateSelect.push($scope.selected[i].id);
            }
        }
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'goods/batch/edit/status',
            data:{
                ids:updateSelect,
                status:$scope.data.status,
                auditFailDescription:$scope.data.auditFailDescription
            },
            method:"PUT"
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }
}]);